<?php
define('IN_D',true);
include('includes/_config.php');
include('includes/_functions.php');
include('includes/_tpl_class.php');
include('includes/_boxes.php');
//require("includes/gain/php_speedy.php");
$func= new func;
$tpl = new Template;


if ($conf['site_off']<>'0') {
	$default_tpl = $conf['default_tpl'];
	$_SESSION['sescurrent_tpl'] = $conf['default_tpl'];
	$contents = (stripslashes($conf['site_off_announcement']));
	$html = $tpl->get_tpl('site_off');
	$html = $tpl->assign_vars($html,array(
			'SITEOFF.INFO'		=>	$contents,
		)
	);
	$tpl->parse_tpl($html);
	exit();
}
//check ONLINE
$number_online = $DB->num_rows($DB->query("SELECT sid FROM ".$conf['prefix']."online WHERE sid = '".SID."'"));
if (!$number_online){
	$DB->query("INSERT INTO ".$conf['prefix']."online (timestamp, sid, ip) VALUES ('".NOW."', '".SID."', '".IP."')");
	$DB->query("UPDATE ".$conf['prefix']."config SET config_value=config_value+1 WHERE config_name='total_visit'");
	$conf['total_visit']+=1;
}
else $DB->query("UPDATE ".$conf['prefix']."online SET timestamp='".NOW."',ip='".IP."' WHERE sid='".SID."'");
//end check
$cmd = array();
	//$cmd=split("/",$_SERVER['PATH_INFO']);
	//if(empty($_GET['act'])) $_GET['act']='main';
	$cmd[1]=(!empty($_GET['act']))?$_GET['act']:"m";
	if(!empty($_GET['id'])) $cmd[2]=$_GET['id'];
	elseif(!empty($_GET['sub'])) $cmd[2]=$_GET['sub'];
	$cmd[3]=(!empty($_GET['p']))?$_GET['p']:"";
	$cmd[4]=(!empty($_GET['keyword']))?$_GET['keyword']:"";
	// TEMPLATE
	if (empty($_COOKIE['DMEDIA_TPL']) || empty($_GET['reset_tpl'])) {
		$default_tpl = $conf['default_tpl'];
		m_setcookie('MEDIA_TPL', $default_tpl);
		$_COOKIE['DMEDIA_TPL'] = $default_tpl;
		if (!empty($_GET['reset_tpl'])) m_refresh();
	}
	if (!empty($change_tpl)) {
		if (!empty($tpl_name))
			m_setcookie('DMEDIA_TPL', $tpl_name);
		m_refresh();
	}



if (empty($url_cur[1])) $_SESSION['current_page'] = RQ_URL;
$current_page = $_SESSION['current_page'];
if ($current_page != RQ_URL) $_SESSION['last_page'] = $current_page;
$_SESSION['current_page'] = RQ_URL;

$logged_in = $func->checkLogin();

if(!empty($_POST['ajaxtype'])){
include("source/ajax.php");
exit();
}

$_SESSION['sescurrent_tpl'] = $_COOKIE['DMEDIA_TPL'];
if(!empty($_SESSION['sescurrent_tpl'])) $_SESSION['sescurrent_tpl'] = $conf['default_tpl'];

switch ($cmd[1]) {
		case 'main': 		include("source/main.php"); break;
		case 'cat': 		include("source/cat.php"); break;
		case 'song': 		include("source/media.php"); break;
		case 'movie': 		include("source/multimedia.php"); break;
		case 'album': 		include("source/multimedia.php"); break;
		case 'singer': 		include("source/singer.php"); break;
		case 'search':  	include("source/search.php"); break;
		case 'contact': 	include("source/contact.php"); break;
		case 'video':   	include("source/autopro.php"); break;
		case 'video-detail':   	include("source/autopro.php"); break;
		case 'user': 		include("source/user.php"); break;
		case 'register':	include("source/user.php"); break;
		case 'playlist':	include("source/playlist.php"); break;
		case 'tivi': 		include("source/tivi.php"); break;
		case 'img': 		include("source/img.php"); exit(); break;
		case 'moviefull': 	include("source/fullscreen.php"); exit(); break;
		case 'ytb': 	include("source/ytb_watch.php"); exit(); break;
		case 'xml': 		include("source/xml.php"); break;
		case 'wpl': 		include("source/wpl.php"); break;
		case 'mtv': 		include("source/mtv.php"); break;
		case 'sms': 		include("source/sms.php"); break;
		default: 			include("source/main.php"); break;
}
	$html_index='';
	$html_index = $tpl->get_tpl('main');
	$js_block = "<script>var web_url=\"{$conf['web_url']}\";</script>\n";
	$js_block .= "<script src='{$conf['web_url']}/js/js.js'></script><script src='{$conf['web_url']}/js/him.js'></script>";
	if (!empty($_SESSION['is_refresh'])) {
		$js_block .= "<script>window.location.href = '#".$_SESSION['last_page']."';</script>";
		unset($_SESSION['is_refresh']);
	}
	$html_index = $tpl->assign_blocks_content($html_index,array(
			'js'		=>	$js_block,
			'main'		=> @$main_content,
		)
	);
	$banner_site="banner.jpg";
	$title_index='';
	if(!empty($title_web_bar) && !empty($title_ascii_web_bar)){
		$title_index=$title_web_bar." | ".$title_ascii_web_bar." | ";
		$desc_key=$title_web_bar.",".$title_ascii_web_bar.",";
	}
	$html_index = $tpl->assign_vars($html_index,array(
			'main.TITLE_WEB_BAR' => @$title_index,
			'main.DESC_KEY'		=> @$desc_key,
			'main.URL_REGISTER'	=> $func->change_link("register",'',"new_register"),
			'main.BANNER'		=> $banner_site,
			'main.URL_LIST_USER'	=> $func->change_link("user","list",$func->title_2_ascii($lang['list_user'],true)),
			'main.URL_TOP_MTV'	=> $func->change_link("mtv","","top_mtv"),
		)
	);
	echo $tpl->parse_tpl($html_index);
	//$compressor->finish();
	exit();
?>